Use global Iterator.prototype for down-level generators#59514
Merged
Conversation
Contributor
Author
|
@typescript-bot: pack this |
Collaborator
Collaborator
|
Hey @rbuckton, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
jakebailey
approved these changes
Aug 5, 2024
Member
jakebailey
left a comment
There was a problem hiding this comment.
This needs a tslib update too, right?
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); |
Member
There was a problem hiding this comment.
I assume it's not a problem if someone redefines the global Iterator, given we don't care if someone does that for other global symbols?
Contributor
Author
Correct. The tslib PR is microsoft/tslib#267 |
magic-akari
added a commit
to magic-akari/swc
that referenced
this pull request
Apr 12, 2025
kdy1
pushed a commit
to swc-project/swc
that referenced
this pull request
Apr 12, 2025
**Related issue:** - Closes #10365 - microsoft/tslib#186 - microsoft/TypeScript#59514
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you are compiling generators with
--target ES5 --lib esnextthe types of those generators will also include the iterator helpers methods likemap,filter, etc., though our down-level generator emit will not have those methods even when running with newer editions of V8 that do support them:Even when not running in latest V8, iterator helpers can be polyfilled, e.g.:
To better support both scenarios, this makes a small change to our
__generatorhelper to use the globalIterator.prototypeobject as the prototype for down-level generators, if it is present.This also does the same for our
__asyncGeneratorhelper when a globalAsyncIterator.prototypeobject is present, even though async iterator helpers are still at Stage 2. Support forAsyncIterator.prototypeseems harmless enough to add at this time but can be postponed to a later PR if necessary.Please note that this will also require the same change in
tslib.Fixes #59513